/**************************************************************
  > File Name: 455.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月06日 星期日 16时53分59秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>


void quickSort(int *num, int L, int R)
{
	if (L >= R)
		return ;
	int left = L;
	int right = R;
	int pivot = num[left];

	while (left < right)
	{
		while (left < right && num[right] >= pivot)
		{
			right--;
		}
		if (left < right)
		{
			num[left] = num[right];
		}

		while (left < right && num[left] <= pivot)
		{
			left++;
		}
		if (left < right)
		{
			num[right] = num[left];
		}

		if (left >= right)
		{
			num[left] = pivot;
		}
	}
	quickSort(num, left + 1, R);
	quickSort(num, L, right - 1);
}


int findContentChildren(int* g, int gSize, int* s, int sSize)
{
	int i, j = 0;

	quickSort(g, 0, gSize - 1);
	quickSort(s, 0, sSize - 1);
	
	for (i = 0; i < sSize; i++)
	{
		if (j < gSize && s[i] >= g[j])
		{
			j++;
		}
	}
	return j;
}

int main(int argc,char **argv)
{
	int a[5] = {1,2,3,4,6};
	int b[4] = {1,1,5,4};
	int ret;

	ret = findContentChildren(a,5,b,4);
	printf("%d\n",ret);
	
    exit(0);
}
